package com.zsc.projectmanagementapi.controller;

import com.zsc.projectmanagementapi.commons.ServerResponse;
import com.zsc.projectmanagementapi.exception.RException;
import com.zsc.projectmanagementapi.pojo.RegisterDAO;
import com.zsc.projectmanagementapi.service.Impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Bernie_fang
 * @Description:
 * @create 2021/6/30 15:10
 **/
@RestController
public class UserController {

    @Autowired
    private UserServiceImpl userService;


    //用户登录
    @PostMapping("/login")
    public ServerResponse login(@RequestParam String username, @RequestParam String password) throws Exception {
        return userService.login(username, password);
    }

    @PostMapping("/register")
    @Transactional(rollbackFor = {Exception.class, RuntimeException.class, RException.class})
    public ServerResponse register(@RequestBody RegisterDAO registerDAO) throws Exception {
        return userService.register(registerDAO);
    }



}
